<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>成语数据库中的20条记录</h1>
<%
String url="jdbc:mysql://localhost:3306/db?serverTimezone=PRC";
//(1)加载驱动
Class.forName("com.mysql.cj.jdbc.Driver");
//(2)创建数据库连接
Connection cn = DriverManager.getConnection(url,"root","12qwas");
//(3)创建预处理语句对象以执行sql指令
PreparedStatement ps = cn.prepareStatement("select * from chengyu limit ?,?");
//(4)设置预处理语句对象中参数的值
ps.setInt(1, 200);
ps.setInt(2, 20);
//(5)执行查询获取记录集
ResultSet rs = ps.executeQuery();
//(6)循环遍历处理记录集
while(rs.next()){
	String cy=rs.getString("cy");
	out.println("<p>"+cy+"</p>");
}
//(7)关闭资源
rs.close();
ps.close();
cn.close();
%>
</body>
</html>
